<!DOCTYPE html>
<html>

	<!-- Mirrored from www.zi-han.net/theme/hplus/table_jqgrid.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 20 Jan 2016 14:20:02 GMT -->

	<head>

		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		<title>三级分类</title>

		<!-- <link rel="shortcut icon" href="favicon.ico"> -->
		<link href="css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
		<link href="css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
		
		<link href="css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
		<link href="css/plugins/iCheck/custom.css" rel="stylesheet">
		<link href="css/animate.min.css" rel="stylesheet">
		<link href="css/style.min862f.css?v=4.1.0" rel="stylesheet">
		<link rel="stylesheet" href="css/cropper.min.css">
		<link rel="stylesheet" href="css/ImgCropping.css">
		<link href="css/newStyle.css" rel="stylesheet">
				
		<style>
			/* 重写bookstrap样式表 勿删 */
			.form_inputs{width: 160px;background-color: #ebebeb;border: 1px solid #06a3f9;border-radius: 20px;-webkit-border-radius: 20px;-moz-border-radius: 20px;-o-border-radius: 20px;-ms-border-radius: 20px;}
			.ibox-title{padding:20px;}
			.ui-jqdialog{height: auto!important;}
			.ui-common-table tbody{background-color: #eaf5fc!important;}
			.modal-dialog{margin: 80px auto!important;}
			.form-group{margin-left:0px!important;margin-right:0px!important;}
			.modal-sm{width: 600px;}
			.col-sm-3{width: 30%;}
			.col-sm-8{width: 70%;}
			.form-horizontal .control-label{text-align: left;padding-top: 5px;font-size: 18px;}
			@media only screen and (min-width: 100px) and (max-width: 600px) {
				.modal-sm{width: 400px;}
				.col-sm-3{width: 40%;}
				.col-sm-8{width: 60%;}
				.scroll_div{width: 85%;}
				.form-horizontal .control-label{text-align: left;padding-top: 5px;font-size: 14px;}
				.dialog_btn{font-size: 14px!important;}
			}
			@media only screen and (min-width: 650px){
				.modal-sm{width: 600px;}
			}
			.refresh_btn{
				width: 80px;
				height: 30px;
				display: flex;
				align-items: center;
				box-sizing: border-box;
				border-width: 1px;
				border-style: solid;
				border-color: rgba(204, 204, 204, 1);
			}
			.refresh_btn a{
				color: #666666;
				margin: 0 auto;
			}
			.opera_btn{
				width: 80px;
				height: 30px;
				align-items: center;
				box-sizing: border-box;
				border: 1px solid rgba(204, 204, 204, 1);
				text-align: center;
				border-radius: 2px;
				background-color: #fff;
			}

			/*以下是等待状态的通用样式*/
			.wating_big_div{position: fixed;top:0px ;width: 100%;height: 100%;display: table;z-index: 9999;}
			.zhezhao{opacity: 0.3;position: absolute;top: 0px;width: 100%;height: 100%;z-index: 9999;}
			.wating_content_div{text-align: center;background:none;display: table-cell;vertical-align: middle;}	
			/*以上是等待状态的通用样式*/
			
			.cache5{
				height: 19px;
				line-height: 19px;
				font-family: '微软雅黑';
				font-weight: 400;
				font-style: normal;
				color: #999999;
				text-align: left;
				border-left: 5px solid rgb(26,188,156);
				padding-left: 5px;
			}
			.c_1ABC9C{
				color: #1ABC9C;
			}
			table thead tr th{
				height: 45px;
				font-family: '微软雅黑 Bold', '微软雅黑 Regular', '微软雅黑';
				font-weight: 700;
				font-style: normal;
				font-size: 14px;
				color: #666666;
				text-align: center;
			}
			#imgPreview {
			  width: 40%;
			  height: 180px;
			  margin: 10px auto 0px auto;
			  border: 1px solid black;
			  text-align: center;
			}
			#prompt3 {
			  width: 100%;
			  height: 180px;
			  text-align: center;
			  position: relative;
			}
			#imgSpan {
			  position: absolute;
			  top: 60px;
			  left: 40px;
			}
			.filepath {
			  width: 100%;
			  height: 100%;
			  opacity: 0;
			}
			#img3 {
			  width: 100%;
			  display: none;
			}
		</style>
	</head>

	<body class="gray-bg">
		<div class="wrapper wrapper-content  animated fadeInRight">
			<div class="row">
				<div class="col-sm-12">
					<div class="ibox ">
						<div class="ibox-title pull-left w100p" style="padding: 10px 20px;">
							<div class="pull-left">
							  <div class="ibox-tools cache5">
							    三级分类
							  </div>
							</div>
							
							<div class="pull-right">
								<button class="refresh_btn">
									<a class="refresh_a" style="">
									  <i class="fa fa-refresh"></i> 刷新
									</a>
								</button>
							</div>
						</div>
						
						
						
						<div class="ibox-content pull-left w100p" style="margin-top: 20px;">
							<div class="ibox-title pull-left w100p" style="background-color: rgb(243, 243, 243);padding: 10px 20px;border-top:0px;">
								<div class="pull-left">
								  <div class="ibox-tools" style="">
									<span class="titleFontIcon"></span>
								    <span class="pull-left" style="position: relative;top: 3px;left: 5px;">数据列表</span>
								  </div>
								</div>
								<div class="pull-right">
									<button class="opera_btn" data-toggle="modal" data-target="#add_dialog">新增</button>
								</div>	
							</div>
		                    
							<div class="pull-left w100p">
								<table class="table table-bordered mb0 " >
		                            <thead>
		                                <tr>
		                                    <th>编号</th>
											<th>分类名称</th>
											<th>级别</th>
											<th>商品数量</th>
											<th>排序</th>
											<th>设置</th>
		                                    <th>操作</th>
		                                </tr>
		                            </thead>
		                            <tbody id="roleManage_list_tbody">
		                            </tbody>
		                        </table>
							</div>
		                    <div class="pull-left tac c0 f14 w100p pre mt10 none" id="footer_page_div">
		        <div class="">
		          
		          <span class="under_line cursor_pointer last_span">上一页</span>
		          <span class="pl20 page_span">1</span>
		          <span class="pl20 under_line cursor_pointer next_span">下一页</span>
		          <span class="pl20">共 <span class="count_page_span">1</span> 页</span>
		          <div class="disib ml20">
		            每页显示：
		            <select class="p0 disib page_select" >
		                            <option value="">10</option>
		                            <option value="" selected="selected">20</option>
		                            <option value="">30</option>
		                          </select>
		                            条
		          </div>
		        </div>
								<div class="record_right_div">
									<!--record_right_div pull-right mt10-->
									数据库总数量： <span class="counts_span">0</span> 条
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<!--新增的弹框-->
		<div class="modal inmodal fade" id="add_dialog" tabindex="-1" role="dialog"  aria-hidden="true">
			<div class="modal-dialog modal-sm">
				<div class="modal-content br8">
					<div class="modal-header p10 bdno" >
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
						<span class="modal-title f18" >添加分类</span>
					</div>
					<div class="modal-body bg_f p0" > 
					  <div class="ibox-content p30">
						  <form class="form-horizontal m-t" id="add_form" method="post" >
							<input type="hidden" name="type" class="add_type" value="1" />
							<div class="form-group " >
								<label class="col-sm-3 control-label pull-left"><span style="color: red;">*</span>分类名称</label>
								<div class="col-sm-8 pull-left">
									<input type="text" class="form-control" name="cateName" value="" required="" aria-required="true">
								</div>
							</div>
						  
							<div class="form-group " >
								<label class="col-sm-3 control-label pull-left">排序：</label>
								<div class="col-sm-8 pull-left">
									<input type="text" class="form-control" name="sort" value="" required="" aria-required="true">
								</div>
							</div>	
							
							<div class="form-group " >
								<label class="col-sm-3 control-label pull-left">一级分类：</label>
								<select name="" class="pull-left h30 br_e5e6e7 f14 getSelect add_parentId" style="width: 120px;height:34px;margin-left: 15px;">
								</select>
							</div>
							
							<div class="form-group " >
								<label class="col-sm-3 control-label pull-left">二级分类：</label>
								<select name="parentId" class="pull-left h30 br_e5e6e7 f14 getSecSelect add_secParentId" style="width: 120px;height:34px;margin-left: 15px;" value="">
								</select>
							</div>
							
							<div class="form-group " >
							  <label class="col-sm-3 control-label pull-left">分类图标:</label>
							  <div class="col-sm-8 pull-left" style="display: flex;align-items: center;">
							    <div style="width: 160px;min-height:50px;background: #eee;">
							      <img class="finalImg" src="" width="100%;">
							      <input type="hidden" class="get_imgurl form-control" name="cateIco" value="" />
							    </div>
							    <div class="replaceImg" style="width:60px;height:30px;line-height:30px;background:#279adf;color:#fff;text-align:center;border-radius:4px;margin-left: 30px;cursor: pointer;">选择图片</div>
							
							    <!-- <div class="" style="width:60px;height:30px;line-height:30px;background:#279adf;color:#fff;text-align:center;border-radius:4px;margin-left: 30px;cursor: pointer;">选择图片</div> -->
							
							    <!-- <input type="file" name="photo" id="photo" value="" placeholder="免冠照片">
							    <input type="button" οnclick="postData();" value="下一步" name="" style="width:100px;height:30px;">
							    <div id="uplddd" name="" style="width:100px;height:30px;background: lightblue;"></div> -->
							
							  </div>  
							</div>
								
							  
							</form>
					  </div>
					</div>
					<div class="modal-footer bdno tac pt0040">
						<button type="button" class=" btn-white clear_btn_style dialog_btn" data-dismiss="modal" >关闭</button>
						<button type="button" class=" btn-primary clear_btn_style bdno dialog_btn ml30" id="add_btn" >保存</button>
						
					</div>
				</div>
			</div>
		</div>
		
		<!--修改的弹框-->
		<div class="modal inmodal fade" id="edit_dialog" tabindex="-1" role="dialog"  aria-hidden="true">
			<div class="modal-dialog modal-sm">
				<div class="modal-content br8">
					<div class="modal-header p10 bdno" >
						<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
						<span class="modal-title f18" >添加分类</span>
					</div>
					<div class="modal-body bg_f p0" > 
					  <div class="ibox-content p30">
						  <form class="form-horizontal m-t" id="edit_form" method="post" >
							<input type="hidden" class="edit_id" name="id" value="1" />
							<input type="hidden" class="edit_type" name="type" value="2" />
							<div class="form-group " >
								<label class="col-sm-3 control-label pull-left"><span style="color: red;">*</span>分类名称</label>
								<div class="col-sm-8 pull-left">
									<input type="text" class="form-control edit_cateName" name="cateName" value="" required="" aria-required="true">
								</div>
							</div>
						  
							<div class="form-group " >
								<label class="col-sm-3 control-label pull-left">排序：</label>
								<div class="col-sm-8 pull-left">
									<input type="text" class="form-control edit_sort" name="sort" value="" required="" aria-required="true">
								</div>
							</div>	
							
							<div class="form-group " >
								<label class="col-sm-3 control-label pull-left">一级分类：</label>
								<select name="" class="pull-left h30 br_e5e6e7 f14 getSelect edit_parentId" style="width: 120px;height:34px;margin-left: 15px;">
								</select>
							</div>
							
							<div class="form-group " >
								<label class="col-sm-3 control-label pull-left">二级分类：</label>
								<select name="parentId" class="pull-left h30 br_e5e6e7 f14 getSecSelect edit_secParentId" style="width: 120px;height:34px;margin-left: 15px;" value="">
								</select>
							</div>
							
							<div class="form-group " >
							  <label class="col-sm-3 control-label pull-left">分类图标:</label>
							  <div class="col-sm-8 pull-left" style="display: flex;align-items: center;">
							    <div style="width: 160px;min-height:50px;background: #eee;">
							      <img class="finalImg" src="" width="100%;">
							      <input type="hidden" class="get_imgurl form-control edit-adpic" name="cateIco" value="" />
							    </div>
							    <div class="replaceImg" style="width:60px;height:30px;line-height:30px;background:#279adf;color:#fff;text-align:center;border-radius:4px;margin-left: 30px;">选择图片</div>
							  </div>  
							</div>
								
							  
							</form>
					  </div>
					</div>
					<div class="modal-footer bdno tac pt0040">
						<button type="button" class=" btn-white clear_btn_style dialog_btn" data-dismiss="modal" >关闭</button>
						<button type="button" class=" btn-primary clear_btn_style bdno dialog_btn ml30" id="edit_btn" >保存</button>
					</div>
				</div>
			</div>
		</div>
		
		<!--修改图片的弹框-->
		<div class="modal inmodal fade" id="preview_media_dialog" tabindex="-1" role="dialog"  aria-hidden="true">
		    <div class="modal-dialog modal-sm">
		        <div class="modal-content br8">
		            <div class="modal-header p10 bdno" >
		                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
		                <span class="modal-title f18" >分类图标:</span>
		            </div>
		            <div class="modal-body bg_f p0" > 
		              <div class="ibox-content p30">
		                  <form class="form-horizontal m-t" id="edit_ad_form" method="post" >
		                    <input type="hidden" class="sysUserId_input" name="sysUserId" id="" value="" />
		                    <input type="hidden" class="id_input" name="id" id="" value="" />
		
		                    <div class="control-label">提示：这里上传的图片不提供剪裁，上传之前请保证图片的尺寸是正确的，支持gif,jpg,png图片的上传</div>
		
		                    <div id="imgPreview">
		                      <div id="prompt3">
		                      <span id="imgSpan">
		                      点击上传
		                        <br />
		                      <i class="aui-iconfont aui-icon-plus"></i>
		                        <!--AUI框架中的图标-->
		                      </span>
		                      <input type="file" id="file" class="filepath" onchange="changepic(this)" accept="image/jpg,image/jpeg,image/png,image/PNG">
		                      <!--当vaule值改变时执行changepic函数，规定上传的文件只能是图片-->
		                      </div>
		                      <img src="#" id="img3" />
		                    </div>
		
		
		                    </form>
		              </div>
		            </div>
		            <div class="modal-footer bdno tac pt0040">
		                <button type="button" class=" btn-white clear_btn_style dialog_btn" data-dismiss="modal" >关闭</button>
		                <button type="button" class=" btn-primary clear_btn_style bdno dialog_btn ml30" id="edit_adPic_btn" >保存</button>
		            </div>
		        </div>
		    </div>
		</div>
		<!--图片裁剪框 start-->
			<div style="display: none;z-index: 9999;" class="tailoring-container">
		  <div class="black-cloth" onclick="closeTailor(this)"></div>
		  <div class="tailoring-content">
		      <div class="tailoring-content-one">
		        <label title="上传图片" for="chooseImg" class="l-btn choose-btn">
		          <input type="file" accept="image/jpg,image/jpeg,image/png" name="file" id="chooseImg" class="hidden" onchange="selectImg(this)">
		          选择图片
		        </label>
		        <div class="close-tailoring"  onclick="closeTailor(this)">×</div>
		      </div>
		      <div class="tailoring-content-two">
		        <div class="tailoring-box-parcel">
		          <img id="tailoringImg">
		        </div>
		        <div class="preview-box-parcel">
		          <p>图片预览：</p>
		          <div class="square previewImg"></div>
		          <div class="circular previewImg"></div>
		        </div>
		      </div>
		      <div class="tailoring-content-three">
		        <button class="l-btn cropper-reset-btn">复位</button>
		        <button class="l-btn cropper-rotate-btn">旋转</button>
		        <button class="l-btn cropper-scaleX-btn">换向</button>
		        <button class="l-btn sureCut" id="sureCut">确定</button>
		      </div>
		    </div>
		</div>
		
		<script src="js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>        
		<script src="js/bootstrap.min.js?v=3.3.6"></script>
		<script src="js/plugins/peity/jquery.peity.min.js"></script>
		<script src="js/content.min.js?v=1.0.0"></script>
		<script src="js/plugins/layer/laydate/laydate.js"></script>
		<script src="js/plugins/sweetalert/sweetalert.min.js"></script>
		<script src="js/plugins/iCheck/icheck.min.js"></script>
		<script src="js/common.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/cropper.min.js"></script>
	
		<script>
			var tableTimeout,addTimeout,setPowerTime,editManageTimeout,deleteTimeOut,getPowerTime,limits = 10,page = 1,counts = 0,table_title,roleID;
			var cherk_roleId;
		      
			var totalPages = 0;
			var maxIndex;
			var picId = "";
			var editPicPath = "";
			
			function changepic() {
			    $("#prompt3").css("display", "none");
			    var reads = new FileReader();
			    f = document.getElementById('file').files[0];
			    reads.readAsDataURL(f);
			    reads.onload = function(e) {
			      document.getElementById('img3').src = this.result;
			      // console.log(this.result);
			      // $.ajax({
			      //   type:"post",
			      //   url:imgUrl+common_url.uploadBase64,
			      //   async:true,
			      //   timeout:30000,
			      //   dataType:"json",
			      //   headers:{
			      //     'X-Access-Token':userMessage.token,
			      //   },
			      //   data:{
			      //     multipart:this.result,
			      //   },
			      //   success:function(json) {
			      //     console.log(json)
			      //     appPicurl = json.result.serverPath;
			      //     console.log(appPicurl);
			      //     editPicPath = appPicurl;
			          
			      //     // $(".get_imgurl").val(appPicurl);
			      //   },
			      //   error:function (xml,text,e) {
			        
			      //   }
			      // });	
			      
			      $("#img3").css("display", "block");
			    };
			    var form = new FormData(); // FormData 对象
			      form.append("multipart", document.getElementById('file').files[0]); // 文件对象
			    // console.log(form);
			    $.ajax({
			      type:"post",
			      url:imgUrl+common_url.uploadFile,
			      async:true,
			      timeout:30000,
			      processData: false,   // jQuery不要去处理发送的数据
			      contentType: false,   // jQuery不要去设置Content-Type请求头
			      headers:{
			        'X-Access-Token':userMessage.token,
			      },
			      data:form,
			      success:function(json) {
			        console.log(json)
			        appPicurl = json.result.serverPath;
			        console.log(appPicurl);
			        editPicPath = appPicurl;
			        
			        // $(".get_imgurl").val(appPicurl);
			      },
			      error:function (xml,text,e) {
			      
			      }
			    });	
			}
			
			$("#uplddd").click(function(){
			    // var formData = new FormData();
			    // formData.append("photo",$("#photo")[0].files[0]);
			    // formData.append("service",'App.Passion.UploadFile');
			    // formData.append("token",token);
			    console.log($("#photo")[0].files[0]);
			    var reader = new FileReader();
			    var AllowImgFileSize = 2100000; //上传图片最大值(单位字节)（ 2 M = 2097152 B ）超过2M上传失败
			    var file = $("#photo")[0].files[0];
			    var imgUrlBase64;
			    if (file) {
			      //将文件以Data URL形式读入页面  
			      imgUrlBase64 = reader.readAsDataURL(file);
			      reader.onload = function (e) {
			        //var ImgFileSize = reader.result.substring(reader.result.indexOf(",") + 1).length;//截取base64码部分（可选可不选，需要与后台沟通）
			        if (AllowImgFileSize != 0 && AllowImgFileSize < reader.result.length) {
			              alert( '上传失败，请上传不大于2M的图片！');
			              return;
			          }else{
			              //执行上传操作
			              // alert(reader.result);
			              console.log(reader.result);
			          }
			      }
			    }
			    console.log(imgUrlBase64);
			    // $.ajax({
			    //   type:"post",
			    //   url:imgUrl+common_url.uploadBase64,
			    //   async:true,
			    //   timeout:30000,
			    //   dataType:"json",
			    //   headers:{
			    //     'X-Access-Token':userMessage.token,
			    //   },
			    //   data:{
			    //     multipart:base64url,
			    //   },
			    //   success:function(json) {
			    //     console.log(json)
			    //     appPicurl = json.result.serverPath;
			    //     console.log(appPicurl)
			    //     $(".get_imgurl").val(appPicurl);
			    //   },
			    //   error:function (xml,text,e) {
			      
			    //   }
			    // });	
			})
			
			//用户头像上传部分：弹出图片裁剪框
			$(".replaceImg").on("click",function () {
				$(".tailoring-container").toggle();
			});
			//图像上传
			function selectImg(file) {
				if (!file.files || !file.files[0]){
					return;
				}
				var reader = new FileReader();
				reader.onload = function (evt) {
					var replaceSrc = evt.target.result;
					//更换cropper的图片
					$('#tailoringImg').cropper('replace', replaceSrc,false);//默认false，适应高度，不失真
				}
				reader.readAsDataURL(file.files[0]);
			}
			//cropper图片裁剪
			$('#tailoringImg').cropper({
				aspectRatio: 16/16,//默认比例
				preview: '.previewImg',//预览视图
				guides: false,  //裁剪框的虚线(九宫格)
				autoCropArea: 0.5,  //0-1之间的数值，定义自动剪裁区域的大小，默认0.8
				movable: false, //是否允许移动图片
				dragCrop: true,  //是否允许移除当前的剪裁框，并通过拖动来新建一个剪裁框区域
				movable: true,  //是否允许移动剪裁框
				resizable: true,  //是否允许改变裁剪框的大小
				zoomable: false,  //是否允许缩放图片大小
				mouseWheelZoom: false,  //是否允许通过鼠标滚轮来缩放图片
				touchDragZoom: true,  //是否允许通过触摸移动来缩放图片
				rotatable: true,  //是否允许旋转图片
				crop: function(e) {
					// 输出结果数据裁剪图像。
				}
			});
			//旋转
			$(".cropper-rotate-btn").on("click",function () {
				$('#tailoringImg').cropper("rotate", 45);
			});
			//复位
			$(".cropper-reset-btn").on("click",function () {
				$('#tailoringImg').cropper("reset");
			});
			//换向
			var flagX = true;
			$(".cropper-scaleX-btn").on("click",function () {
				if(flagX){
					$('#tailoringImg').cropper("scaleX", -1);
					flagX = false;
				}else{
					$('#tailoringImg').cropper("scaleX", 1);
					flagX = true;
				}
				flagX != flagX;
			});
			//裁剪后的处理
			$("#sureCut").on("click",function () {
				if ($("#tailoringImg").attr("src") == null ){
					return false;
				}else{
					var cas = $('#tailoringImg').cropper('getCroppedCanvas');//获取被裁剪后的canvas
					var base64url = cas.toDataURL('image/png'); //转换为base64地址形式
					$("#add_form .finalImg").prop("src",base64url);//显示为图片的形式
					$("#edit_form .finalImg").prop("src",base64url);//显示为图片的形式
					
					let blob= dataURLtoFile(base64url,'image/jpeg');
					let form = new FormData();
					form.append("bizType","9");
					let fileOfBlob = new File([blob], new Date()+'.jpg'); // 重命名了
					form.append("file", fileOfBlob);
					
					$.ajax({  
						url : uploadImgUrls,  
						type: 'post',
                        data: form,
                        dataType: "json",
                        async: false,
                        cache: false,
                        contentType: false,
                        processData: false,
						success:function(data){  
							CheckLogout(data); //检查是否登陆过期
							console.log(data.root);
							$(".get_imgurl").val(data.root);
						},  
						error:function (xml,text,e) {
						
						}
				
					});
			
			// 		console.log(base64url);
			// 		$(".get_imgurl").val(base64url);
			
			// 		var appPicurl;
			// 		$.ajax({
			// 			type:"post",
			// 			url:uploadImgUrls,
			// 			async:true,
			// 			timeout:30000,
			// 			dataType:"json",
			// 			headers:{
			// 				// 'X-Access-Token':userMessage.token,
			// 			},
			// 			data:{
			// 				multipart:base64url,
			// 			},
			// 			success:function(json) {
			// 				console.log(json)
			//   appPicurl = json.result.serverPath;
			//   console.log(appPicurl)
			// 				$(".get_imgurl").val(appPicurl);
			// 			},
			// 			error:function (xml,text,e) {
						
			// 			}
			// 		});	
			
					//关闭裁剪框
					closeTailor();
				}
			});
			//关闭裁剪框
			function closeTailor() {
				$(".tailoring-container").toggle();
			}
			
			
			$(document).ready(function() {
				IsTokenSave();
				var userMessage = JSON.parse(sessionStorage.getItem("user_message"));
				//用户头像上传部分：弹出框水平垂直居中
					var win_height = $(window).height();
					var win_width = $(window).width();
					if (win_width <= 768){
						$(".tailoring-content").css({
							"top": (win_height - $(".tailoring-content").outerHeight())/2,
							"left": 0
						});
					}else{
						$(".tailoring-content").css({
							"top": (win_height - $(".tailoring-content").outerHeight())/2,
							"left": (win_width - $(".tailoring-content").outerWidth())/2
						});
				}
				
				InitTbodyList(page);//初始化列表数据
				getSelect();//获取下拉列表数据
				
				$(".refresh_a").click(function(){//刷新按钮
		    		location.reload();        		
		    	});
		    	$(".i-checks").iCheck({  //check必须有的脚本
					checkboxClass: "icheckbox_square-green",
					radioClass: "iradio_square-green",
				});
				
				$("#check_btn").click(function () {//查询按钮
					powerName = $("#check_input").val();
					page = 1;//重置页数
					$(".role_page_span").html(1);//重置页数
					InitTbodyList(page);//获取列表数据
				});
							
				$(".page_select").change(function() { //选择一页多少条数据的select
					page = 1;//重置页数
					$(".page_span").html(1);//重置页数
					limits = $(".page_select option:selected").text();  //设置当前显示数量
					InitTbodyList(page);
				});
		
				$(".last_span").click(function() {  //上一页
					if (page < 2) {
						TipsAlert("这是最前面的数据了");
						return false;
					}
					page--;
					$(".page_span").html(parseInt($(".page_span").html()) - 1);
					InitTbodyList(page);
				});		
				$(".next_span").click(function() { //下一页
				
					if (page > maxIndex - 1) {
						TipsAlert("这是最后面的数据了");
						return false;
					}
					page++;
					$(".page_span").html(parseInt($(".page_span").html()) + 1);
					InitTbodyList(page);
				});
				
				
				$("#add_btn").click(function () { //添加的保存按钮
					if ($("#add_form .form-control").eq(0).val().trim() == "") {
						TipsAlert("分类名称不能为空");
						return false;
					}
					if ($('.add_parentId').val() == "") {
						TipsAlert("必须选择一级菜单");
						return false;
					}
					if ($('.secParentId').val() == "") {
						TipsAlert("必须选择二级菜单");
						return false;
					}
					console.log($("#add_form .form-control"));
					Showload("正在初始化列表......");
					addTimeout = setInterval("Timeout(addTimeout)", 1000);
					$.ajax({
						type:"post",
						url:urls+ common_url.bsysGoodsCate_create,
						async:true,
						timeout:30000,
						dataType:"json",
						headers:{
							'X-Access-Token':userMessage.token,
						},
						data:$("#add_form").serialize(),
						success:function  (json) {
							CheckLogout (json);//检查是否登陆过期
							if (json.code == 0) {
								swal({
								    title: "添加成功",
								    text: "添加成功",
								    type: "success",
								},function () {
									location.reload();
								});
							} else{
								TipsAlert(json.msg);
							}
							InitTime (addTimeout);
						},
						error:function(xml, text, errorThrown) {
							if (text == "timeout") {
								TipsAlert("请求超时,请检查网络或着重新打开该页面.");
							} else{
								TipsAlert("请求数据失败,请联系后台技术人员");
							}
							InitTime (addTimeout);
						}
					});
				});
				
				$("#edit_btn").click(function () { //修改的保存按钮
					if ($("#edit_form .form-control").eq(0).val().trim() == "") {
						TipsAlert("分类名称不能为空");
						return false;
					}
					
					// $("#add_form .createBy_input").val(userMessage.userInfo.username);
					console.log(userMessage);
					console.log($("#edit_form").serialize());
					Showload("正在初始化列表......");
					addTimeout = setInterval("Timeout(addTimeout)", 1000);
					$.ajax({
						type:"post",
						url:urls+ common_url.bsysGoodsCate_update,
						async:true,
						timeout:30000,
						dataType:"json",
						headers:{
							'X-Access-Token':userMessage.token,
						},
						data:$("#edit_form").serialize(),
						success:function  (json) {
							CheckLogout (json);//检查是否登陆过期
							if (json.code == 0) {
								swal({
								    title: "修改成功",
								    text: "修改成功",
								    type: "success",
								},function () {
									location.reload();
								});
							} else{
								TipsAlert(json.return_msg);
							}
							InitTime (addTimeout);
						},
						error:function(xml, text, errorThrown) {
							if (text == "timeout") {
								TipsAlert("请求超时,请检查网络或着重新打开该页面.");
							} else{
								TipsAlert("请求数据失败,请联系后台技术人员");
							}
							InitTime (addTimeout);
						}
					});
				});
				
				$('.add_parentId').change(function() {
				  console.log($(this).val())
				  getSecSelect($(this).val())
	
				});
				$('.edit_parentId').change(function() {
				  console.log($(this).val())
				  getSecSelect($(this).val())
				});
				$(".add_secParentId").change(function() {
				  console.log($(this).val())
				  // getSecSelect($(this).val())
				  // tequanIndex = $(this).val();
					// if ($(this).val() == '') {
					// 	console.log(123123)
					// 	TipsAlert("请先选择一级分类");
					// 	return false;
					// }
				  //   $(this).attr("checked",true);
				  //   $(this).val(1);
				  // }else{
				  //   $(this).attr("checked",false);
				  //   $(this).val(0);
				  // }
				});
		       
				$(".edit_secParentId").change(function() {
					console.log($(this).val())
		
				});
			   		       
				
			});
			
			/**
			 * 该方法用于初始化列表
			 * @param {Number} startIndex startIndex是数据起始下标
			 * */
			function InitTbodyList (startIndex) {
				Showload("正在初始化列表......");
				var add_type = 3;
				$(".add_type").val(add_type);
				$(".edit_type").val(add_type);
				tableTimeout = setInterval("Timeout(tableTimeout)", 1000);
				$.ajax({
					type:"get",
					url:urls+ common_url.bsysGoodsCate_list,
					async:true,
					timeout:30000,
					dataType:"json",
					headers: {
						'X-Access-Token': userMessage.token,
					},
					data:{
						type:add_type,
						page:startIndex,
						limit:limits
					},
					success:function  (json) {
						console.log(json);
						CheckLogout (json);//检查是否登陆过期
						if (json.code == 0 ) {
							totalPages = json.data.records.total;
							var myData = json.data.records;
							var tableHtml = "";
							counts = json.data.total;
							console.log(myData);
							if (counts == 0) { //显示或隐藏分页
								$("#footer_page_div").hide();
							} else{
								$("#footer_page_div").show();
							}
							maxIndex = (counts / limits).toCeil(0);
							$(".count_page_span").html(maxIndex); //设置当前共几页  
							$(".counts_span").html(counts);
							for (var i = 0; i < myData.length; i++) {
								if(myData[i]["show_bar"] == 1){//1:
									myData[i]["show_bar_text"] = "否"
								}else{
									myData[i]["show_bar_text"] = "是"
								}
								
								if(myData[i]["show_goods"] == 1){//1:
									myData[i]["show_goods_text"] = "否"
								}else{
									myData[i]["show_goods_text"] = "是"
								}
									
								tableHtml = tableHtml + '<tr>'
											+ '<td data-cateico="'+myData[i]["cate_ico"]+'" data-erji="'+myData[i]["erji"]+'" data-yiji="'+myData[i]["yiji"]+'" data-id="'+myData[i]["id"]+'" data-cateName="'+myData[i]["cate_name"]+'" data-sort="'+myData[i]["sort"]+'" data-parentid="'+myData[i]["parent_id"]+'">'+myData[i]["id"]+'</td>'
											+ '<td>'+myData[i]["cate_name"]+'</td>'
											+ '<td>'+myData[i]["type"]+'</td>'
											+ '<td class="c_1ABC9C">'+myData[i]["number"]+'</td>'
											+ '<td>'+myData[i]["sort"]+'</td>'
											+ '<td>'
											+ '</td>'
											+ '<td>'
												+ '<span class="under_line cursor_pointer edit_span pl20 c_1ABC9C" data-toggle="modal" data-target="#edit_dialog">编辑</span>'
												+ '<span class="under_line cursor_pointer delete_span pl20 c_1ABC9C" >删除</span>'
											+ '</td>'
										+ '</tr>';
							}
							$("#roleManage_list_tbody").html(tableHtml);
							DealTable();
							InitFunc();
						}else{
							TipsAlert(json.code);
							// if (json.return_msg == "Session过期") {
							// 	window.location = "login_timeout.html";
							// }else{
							// 	TipsAlert(json.return_msg);
							// }
						}
						InitTime (tableTimeout);
					},
					error:function(xml, text, errorThrown) {
						if (text == "timeout") {
							TipsAlert("请求超时,请检查网络或着重新打开该页面.");
						} else{
							TipsAlert("请求数据失败,请联系后台技术人员");
						}
						InitTime (tableTimeout);
					}
					
				});
			}
			
			/**
			 * 该方法用于获取下拉列表数据
			 * @param {Number} token是获取数据的必传参数
			* */
			function getSelect() { 
				$.ajax({
					type:"get",
					url:urls+ common_url.oneCatelist,
					async:true,
					timeout:30000,
					dataType:"json",
					headers:{
						'X-Access-Token':userMessage.token,
					},
					data:{
						parentId:''
					},
					success:function  (json) {
						console.log(json);
						CheckLogout (json);//检查是否登陆过期		
						if (json.code == 0) {
							var optionHtml = '<option value="">全部</option>';
							var myData = json.data;
							for (var i = 0; i < myData.length; i++) {
								optionHtml = optionHtml + '<option value="' + myData[i]["id"] + '">' + myData[i]["cateName"] + '</option>';
							}
							$(".getSelect").html(optionHtml);
						} else{
							$(".getSelect").html('<option value="">获取菜单失败</option>');
						}
				
						InitTime (tableTimeout);
					},
					error:function(xml, text, errorThrown) {
						if (text == "timeout") {
							TipsAlert("请求超时,请检查网络或着重新打开该页面.");
						} else{
							TipsAlert("请求数据失败,请联系后台技术人员");
						}
						InitTime (tableTimeout);
					}
				})
			}
			
			function getSecSelect(parentId) {
				$.ajax({
					type:"get",
					url:urls+ common_url.oneCatelist,
					async:true,
					timeout:30000,
					dataType:"json",
					headers:{
						'X-Access-Token':userMessage.token,
					},
					data:{
						parentId:parentId
					},
					success:function  (json) {
						console.log(json);
						CheckLogout (json);//检查是否登陆过期		
						if (json.code == 0) {
							var optionHtml = '<option value="">全部</option>';
							var myData = json.data;
							for (var i = 0; i < myData.length; i++) {
								optionHtml = optionHtml + '<option value="' + myData[i]["id"] + '">' + myData[i]["cateName"] + '</option>';
							}
							$(".getSecSelect").html(optionHtml);
						} else{
							$(".getSecSelect").html('<option value="">获取菜单失败</option>');
						}
				
						InitTime (tableTimeout);
					},
					error:function(xml, text, errorThrown) {
						if (text == "timeout") {
							TipsAlert("请求超时,请检查网络或着重新打开该页面.");
						} else{
							TipsAlert("请求数据失败,请联系后台技术人员");
						}
						InitTime (tableTimeout);
					}
				})
			}
			
		
			/**
			 * 该方法用于初始化操作列里的事件
			 * */
			function InitFunc () {  	
				$(".edit_span").each(function() { //编辑按钮
					$(this).click(function() {
						var dataset = $(this).parents("td").siblings("td").eq(0)[0].dataset;
						console.log(dataset)
						$("#edit_form .edit_id").val(dataset.id);
						$("#edit_form .edit_cateName").val(dataset.catename);
						$("#edit_form .edit_sort").val(dataset.sort);
						$("#edit_form .edit_parentId").val(dataset.yiji);
						$("#edit_form .finalImg").attr("src",imgUrl+dataset.cateico);
						// getSecSelect(dataset.yiji);
						$.ajax({
							type:"get",
							url:urls+ common_url.oneCatelist,
							async:true,
							timeout:30000,
							dataType:"json",
							data:{
								parentId:dataset.yiji
							},
							success:function  (json) {
								// CheckLogout (json);//检查是否登陆过期		
								if (json.code == 0) {
									var optionHtml = '<option value="">全部</option>';
									var myData = json.data;
									for (var i = 0; i < myData.length; i++) {
										optionHtml = optionHtml + '<option value="' + myData[i]["id"] + '">' + myData[i]["cateName"] + '</option>';
									}
									$(".getSecSelect").html(optionHtml);
									$("#edit_form .edit_secParentId").val(dataset.erji);
								} else{
									$(".getSecSelect").html('<option value="">获取菜单失败</option>');
								}
								
								InitTime (tableTimeout);
							},
							error:function(xml, text, errorThrown) {
								if (text == "timeout") {
									TipsAlert("请求超时,请检查网络或着重新打开该页面.");
								} else{
									TipsAlert("请求数据失败,请联系后台技术人员");
								}
								InitTime (tableTimeout);
							}
						})
						
					});
				});//编辑按钮结束括号
				
				
				$(".delete_span").each(function () {//删除按钮
					$(this).click(function () {
						var dataset = $(this).parents("td").siblings("td").eq(0)[0].dataset;
						console.log(JSON.parse(sessionStorage.getItem("user_message")));
						var userMessage = JSON.parse(sessionStorage.getItem("user_message"));
						console.log(userMessage.token);
						swal({
						    title: "请再次确认是否删除？",
						    text: "删除后将无法恢复，请谨慎操作！",
						    type: "warning",
						    showCancelButton: true,
						    confirmButtonColor: "#DD6B55",
						    confirmButtonText: "是的，确定删除",
						    cancelButtonText: "让我再考虑一下…",
						    closeOnConfirm: false,
						    closeOnCancel:true
						}, function (yes) {
							if (yes) {
								Showload("正在请求删除，请稍后....");
								deleteTimeOut = setInterval("Timeout(deleteTimeOut)", 1000);
								$.ajax({
									type:"post",
									url:urls + common_url.bsysGoodsCate_delete,
									async:true,
									timeout:30000,
									dataType:"json",
									headers:{
										'X-Access-Token':userMessage.token,
									},
									data:{id:dataset.id},
									success:function(json) {
										console.log(json);
										CheckLogout (json);
										if (json.code == 0) {
											swal({
											    title: "删除成功",
											    text: "删除成功",
											    type: "success",
											},function () {
												location.reload();
											});
										}
										InitTime (deleteTimeOut);
									},
									error:function (xml,text,e) {
										if (text == "timeout") {
											TipsAlert("请求超时,请检查网络或着重新操作");
										} else{
											TipsAlert("请求数据失败,请联系后台技术人员");
										}
										InitTime (deleteTimeOut);
									}
								});
							} 
						});
						
					});	
				});//删除按钮结束括号
			}
			
			
		
		</script>

			
	</body>
</html>